﻿using FreesenseSubAIS.Core;
using FreesenseSubAIS.ImageProcess;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FreesenseSubAIS.UI
{
    public partial class FormUser : Form
    {
        private Bitmap btt;
        bool bl;
        public FormUser()
        {
            InitializeComponent();
        }
        public Bitmap m_bitmap
        {
            get
            {
                return btt;
            }
            set
            {

                if (btt != null)
                {
                    btt.Dispose();
                }
                btt = value;
                if (value != null)
                    DisPic(btt);
            }

        }

        private void DisPic(Bitmap btt)
        {
            if (bl)
            {
                imageShow_c1.m_bmp = btt;
            }
        }
        private void load_Btn_Click(object sender, EventArgs e)
        {
            imageShow_c1.Loads();
        }

        private void SetExtime_Btn_Click(object sender, EventArgs e)
        {
            int time = 1000;
            if (int.TryParse(toolStripTextBox1.Text, out time))
            {
                if (time > 14 && time < 7000000)
                {
                    ImageManage.Instance.SetExposureTime(new string[] { toolStripComboBox1.Text }, new double[] { time });
                }
            }
        }

        private void FormUser_Load(object sender, EventArgs e)
        {
            bl = true;
            var source = Device.DeviceEntityControl.Cameras.Select(x => x.CameraName).ToList();
            source.ForEach(x => toolStripComboBox1.Items.Add(x));
        }

        private void FormUser_FormClosing(object sender, FormClosingEventArgs e)
        {
            bl = false;
        }
    }
}
